package fudan.se.project.controller.account.user;


import fudan.se.project.controller.request.InvitationAcceptRequest;
import fudan.se.project.controller.request.OnlyIdPropertyRequest;
import fudan.se.project.service.advanced.account.user.UserInvitationService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;

/**
 * @author Gao Longchao
 */
@Slf4j
@RestController
@RequestMapping("/user/message")
public class UserInvitationController {

    private final UserInvitationService userInvitationService;

    @Autowired
    public UserInvitationController(UserInvitationService userInvitationService) {
        this.userInvitationService = userInvitationService;
    }

    @GetMapping("/invitations/sent")
    public ResponseEntity<?> invitationsSent(@Min(1) @RequestParam int page) {

        return userInvitationService.invitationsSent(page);
    }

    @GetMapping("/invitations/received")
    public ResponseEntity<?> invitationsReceived(@Min(1) @RequestParam int page) {

        return userInvitationService.invitationsReceived(page);
    }


    @PostMapping("/acceptInvitation")
    public ResponseEntity<?> acceptInvitation(@Validated @RequestBody InvitationAcceptRequest request) {

        return userInvitationService.acceptInvitation(request);
    }

    @PostMapping("/rejectInvitation")
    public ResponseEntity<?> rejectInvitation(@RequestBody OnlyIdPropertyRequest request) {

        return userInvitationService.rejectInvitation(request);
    }
}
